import types from '../types.js'

// initial state
const state = {
  value: localStorage.getItem(types.TOKEN)
}

// getters
const getters = {
  
  getToken: state => state.value,
  
  verifyToken: state => {
    if(!state.value) {
      return false
    }
    return true
  }
}

// actions
const actions = {}

// mutations
const mutations = {
  
  setToken(state, value) {
    localStorage.setItem(types.TOKEN, value)
    state.value = value
  },
  
  clearToken(state, value) {
    localStorage.removeItem(types.TOKEN)
    state.value = ''
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
